<?php

namespace app\admin\controller\zzarticle;

use addons\zzarticle\model\ArticleM;
use app\common\controller\Backend;

class Article extends Backend
{
    protected $model          = null;
    protected $relationSearch = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new ArticleM();
        $searchList  = [
            'status' => [
                'normal' => '正常',
                'hidden' => '隐藏',
            ],
            'banner' => [
                'y' => '是',
                'n' => '否',
            ],
        ];
        $this->assign('statusList', $searchList['status']);
        $this->assignconfig('searchList', json_encode($searchList));
    }

    public function index()
    {
        $this->request->filter(['strip_tags', 'trim']);
        if (false === $this->request->isAjax()) {
            return $this->fetch();
        }
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model->with([
            'type',
        ])->where($where)->order($sort, $order)->paginate($limit);
        return json([
            'total' => $list->total(),
            'rows'  => $list->items(),
        ]);
    }
}
